function lubo() {
    //判断索引 如果index已经到最后一个,就把它赋值0
    //结果 = 条件表达式?真:假;
    index = index == 5 ? 0 : ++index;
    //当前状态
    nowzt(index);
}
function nowzt(index) {
    //更新轮标class
    $('.nav li').eq(index).addClass('on').siblings().removeClass('on');
    //轮播图片
    $('.pic li').eq(index).fadeIn().siblings().hide();
}
var url = "http://hengzhi.ayvvv.com";
// 三级分类信息循环开始
$.ajax({
    url: url + "/api/store/product/category/lst",
    dataType: "json",
    type: "get",
    async: true,
    success: function (sort) {
        for (var i = 0; i < sort.data.length; i++) {
            $('.sort_ul').append(`<li class="li1"><div class="mulu"><a href="javascript:;">` + sort.data[i].cate_name + `</a><div class="jian"></div>
                            <div class="bai"></div>
                            </div>
                            <div class="hidemenu">
                            <div class="hideleftt" id="sort_class`+ i + `">
                            </div>
                    </div>
                </li>
                `);
            for (var j = 0; j < sort.data[i].children.length; j++) {
                $('#sort_class' + i + '').append(`<dl class="dll" >  
                                <dt><a href="javascript:;" style=" color: red;text-decoration:none" >`+ sort.data[i].children[j].cate_name + `</a></dt>
                                <span id="sort_classs`+ i + j + `"></span>                 
                            </dl>`);
                for (var l = 0; l < sort.data[i].children[j].children.length; l++) {
                    $('#sort_classs' + i + j + '').append(`<dt><a style="text-decoration:none"  href="list.html?cate_id=` + sort.data[i].children[j].children[l].store_category_id + `">` + sort.data[i].children[j].children[l].cate_name + `</a></dt>`);
                }
            }
        }



    },
    error: function () { }
});
// 三级分类信息循环结束

// 首页内容渲染开始  链接未填写
$.ajax({
    url: url + "/api/common/home",
    dataType: "json",
    type: "get",
    async: true,
    success: function (data) {
        // 导航栏开始
        var v = data.data.menu;
        for (var i = 0; i < v.length; i++) {
            $('.dhright').children().first().append('<li><a href="javascript:;" title="' + v[i].name + '">' + v[i].name + '</a></li>');
        }
        // 导航栏结束
        // banner图开始
        var banner = data.data.banner;
        for (var i = 0; i < banner.length; i++) {
            var ii = i + 1;
            if (i == 0) {
                $('.pic').append(`<li style="display:block"><a href="` + url + banner[i].url + `"><img src="` + banner[i].pic + `" alt=""  style="height:400px;width: 670px;"/></li>`);
                $('.nav').append(`<li class="on">` + ii + `</li>`);
            } else {
                $('.pic').append(`<li><a href="` + url + banner[i].url + `"><img src="` + banner[i].pic + `" alt=""  style="height:400px;width: 670px;"/></li>`);
                $('.nav').append(`<li>` + ii + `</li>`);
            }

        }
        $('.nav li').mouseover(function () {
            clearInterval(time);
            index = $(this).index();
            nowzt(index);

        });


        $('.nav li').mouseout(function () {
            time = setInterval(lubo, 3000);
        });


        $('.pic li').mouseover(function () {
            var time = setInterval(lubo, 3000);
            clearInterval(time);
            index = $(this).index();
            nowzt(index);
        });


        $('.pic li').mouseout(function () {
            time = setInterval(lubo, 3000);
        });

        // banner图结束
        // banner图下面的推荐hot开始
        // var b_hot=data.data.hot;
        // for (var i = 0; i < b_hot.length; i++) {
        //     $('#b_hot').append('<li><a href="'+url+b_hot[i].url+ '" title="'+b_hot[i].title+ '"><img src="'+b_hot[i].pic+ '"/></a></li>');
        // }
        // banner图下面的推荐hot结束
    },
    error: function () { }
});
// 首页内容渲染结束

//轮播图片的获取
$.ajax({
    url: url + "/api/common/home",
    dataType: "json",
    type: "get",
    async: true,
    success: function (newdata) {

        var newbanner = newdata.data.banner;
        for (var i = 0; i < newbanner.length; i++) {

            $('#newlunbo').append(`<div class="swiper-slide">
<img  style="width:100%;height:100%" src="` + newbanner[i].pic + `" alt=""  style="height:400px;width: 670px;"/></div>`);



        }
    }
})
// 首页商品加载开始  链接未填写
// 加载分类ajax开始
$.ajax({
    url: url + "/api/store/product/category/lst",
    dataType: "json",
    type: "get",
    async: true,
    success: function (sort) {
        console.log(sort);
        for (var i = 0; i < sort.data.length; i++) {
            var ii = i + 1;
            $('#the_shop_floor').append(`<!-- 楼层开始 -->
<div id="onefloor">

<!-- 楼层顶部开始 -->

    <div class="one_top">

        <div class="louceng">
            <h2>`+ sort.data[i].cate_name + `</h2>
            <div class="lou"><span>`+ ii + `F</span></div>

        </div>
    </div>

<!-- 楼层顶部结束 -->

    <div class="onemain">

    <!-- 楼层左边开始 -->

        <div class="mainleft">

            <ul class="floor_left`+ i + `">

                <!--<li><a href="">左侧栏</a></li>-->


            </ul>

            <div class="lefttu">

                <img src="images/e13.jpg" alt="" />

            </div>

        </div>

        <!-- 楼层左边结束 -->



        <!-- 楼层中间开始 -->

        <div class="maincenter">

        <!-- 楼层特价商品开始 -->

            <!-- 楼层大家电开始 -->
            <div class="cent1 floor_center`+ sort.data[i].children[0].children[0].store_category_id + `" id="floor_center` + i + `" style="display:block">
            </div>
            <!-- 楼层大家电结束 -->
        </div>
        <!-- 楼层中间结束 -->
        <!-- 楼层右侧开始 -->

        <div class="mainright">
            <span style="color: #cf3a3a;text-align: center;"><h3>热销排行</h3></span>
            <div class="centu floor_right`+ sort.data[i].children[0].children[0].store_category_id + `" id="floor_right` + i + `">
            </div>

        </div>

        <!-- 楼层右侧结束 -->

    </div>
</div>
    <!-- 楼层结束 -->`);
            // console.log(sort.data[i].store_category_id);
            // 楼层左侧数据开始
            for (var k = 0; k < sort.data[i].children.length; k++) {
                $(`.floor_left` + i + ``).append(`<li floor="` + i + `" class="floor_left_click" underfirstid="` + sort.data[i].children[k].children[0].store_category_id + `" ><a href="javascript:;">` + sort.data[i].children[k].cate_name + `</a></li>`);
            }
            // 楼层左侧数据结束

            // 加载对应分类的商品开始
            function center_product(store_id) {

                $.ajax({
                    url: url + '/api/store/product/lst?cate_id=' + store_id + '&order=&price_on=&price_off=&brand_id=&keyword=&page=1&limit=10',
                    dataType: "json",
                    type: "get",
                    async: true,
                    success: function (product_data) {
                        console.log(product_data, "333333")
                        for (var i = 0; i < product_data.data.list.length; i++) {

                            $(`.floor_center` + store_id + ``).append(` <div class="centu" >
                            <a style="text-decoration:none"   href="goods.html?product_id=`+ product_data.data.list[i].product_id + `&brand_id=` + product_data.data.list[i].brand_id + `&cate_id=` + product_data.data.list[i].cate_id + `">
                                    <div class="tu">

                                        <img src="`+ product_data.data.list[i].image + `" alt="" style="height:100px;width: 100px;" />

                                    </div>

                                    <div class="p_name">

                                        ` + product_data.data.list[i].store_name + `

                                    </div>

                                    <div class="price">

                                        <span style="color:#E4393C">￥<b style="font-size:16px">`+ product_data.data.list[i].price + `</b></span>

                                    </div>
                                    </a>

                                </div>`);
                        }

                    },
                    error: function () { }
                });
            }
            center_product(sort.data[i].children[0].children[0].store_category_id)
            // 加载对应分类的商品结束
            // 加载对应分类的热卖商品开始
            function right_product(store_id) {
                $.ajax({
                    url: url + '/api/store/product/lst?cate_id=' + store_id + '&order=sales&price_on=&price_off=&brand_id=&keyword=&',
                    dataType: "json",
                    type: "get",
                    data: { page: 1, limit: 2 },
                    async: true,
                    success: function (product_data) {
                        for (var i = 0; i < product_data.data.list.length; i++) {
                            $(`.floor_right` + store_id + ``).append(`<div  class="tu">
                            
                                                <img  src="`+ product_data.data.list[i].image + `" alt="" style="height:100px;width: 100px;" />
                                            </div>
                                            <div class="p_name">
 <a href="goods.html?product_id=`+ product_data.data.list[i].product_id + `&brand_id=` + product_data.data.list[i].brand_id + `&cate_id=` +
                                product_data.data.list[i].cate_id + `">` + product_data.data.list[i].store_name + `</a>
                                            </div>
                                            <div class="price">
                                                <span style="color:#E4393C">￥<b style="font-size:16px">`+ product_data.data.list[i].price + `</b></span>
                                            </div>`);
                        }

                    },
                    error: function () { }
                });
            }
            right_product(sort.data[i].children[0].children[0].store_category_id)
            // 加载对应分类的热卖商品结束


        };
        $('.floor_left_click').click(function () {
            var store_id = $(this).attr("underfirstid");
            var floor_id = $(this).attr("floor");
            $(`#floor_center` + floor_id + ``).empty()
            $(`#floor_center` + floor_id + ``).removeClass()
            $(`#floor_center` + floor_id + ``).addClass(`cent1`)
            $(`#floor_center` + floor_id + ``).addClass(`floor_center` + store_id + ``)
            center_product(store_id)
            $(`#floor_right` + floor_id + ``).empty()
            $(`#floor_right` + floor_id + ``).removeClass()
            $(`#floor_right` + floor_id + ``).addClass(`centu`)
            $(`#floor_right` + floor_id + ``).addClass(`floor_right` + store_id + ``)
            right_product(store_id)


        })


    },
    error: function () { }
});
    // 加载分类ajax结束
 // 首页商品加载结束.


